package com.dfbz.demo02_BigDecimal;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */

public class Demo02_BigDecimal常用方法 {

    public static void main(String[] args) {
        BigDecimal num1 = new BigDecimal("10");
        BigDecimal num2 = new BigDecimal("3");

        System.out.println(num1.divide(num2,BigDecimal.ROUND_UP));          // 4
        System.out.println(num1.divide(num2,BigDecimal.ROUND_DOWN));          // 3
        System.out.println(num1.divide(num2,BigDecimal.ROUND_CEILING));          // 4
        System.out.println(num1.divide(num2,BigDecimal.ROUND_UP));          // 3

        /* BigDecimal对于结果是无线循环小数,需要指定策略来清除小数点后面的位数,否则出现异常
            否则出现异常:  java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
         */
        System.out.println(num1.divide(num2));          // 3
    }

    public static void test(String[] args) {

        BigDecimal num1 = new BigDecimal("10");
        BigDecimal num2 = new BigDecimal("2");

        System.out.println(num1.add(num2));
        System.out.println(num1.subtract(num2));
        System.out.println(num1.multiply(num2));
        System.out.println(num1.divide(num2));

    }
}
